var status = -1;

function action(g, c, b) {
    status++;
    var e = cm.getNumberFromQuestInfo(42011, "time", 600000);
    cm.updateHeaderUI(1, 0, e, 0, e, 42011);
    var d = cm.getNumberFromQuestInfo(42002, "f");
    var a = cm.getNumberFromQuestInfo(42002, "t", 99999999);
    if (d <= 0) {
        cm.dispose();
        return
    }
    if (a == 99999999) {
        if (status == 0) {
            cm.curNodeEventEnd(true);
            cm.setInGameDirectionMode(true, true);
            cm.setStandAloneMode(true);
            cm.sendNext("#h # ，塔的里面怎么样？", 2540000)
        } else {
            if (status == 1) {
                cm.sendNext("看你在塔中努力的冒险，就给你一份小小的礼物吧。", 2540000)
            } else {
                if (status == 2) {
                    cm.sendOk("戒指箱，起源之塔荣誉勋章，经验值，起源点数全部都已经发放了，打开消耗栏确认一下吧。", 2540000)
                } else {
                    if (status == 3) {
                        reward()
                    }
                }
            }
        }
    } else {
        if (status == 0) {
            cm.curNodeEventEnd(true);
            cm.setInGameDirectionMode(true, true);
            cm.sendNext("#h # ，塔的里面怎么样？", 2540000)
        } else {
            if (status == 1) {
                cm.sendNext("#h # ，即便使用了朦胧石，依然在回来之前剩余了许多时间啊，虽然我没法将时间完全逆转，但是我可以尝试将剩余时间的一半重新做成石头。\r\n\r\n另外我能够重新研磨的最大时长是所使用的朦胧石时间的一半，如果增加了90分钟就是45分钟。", 2540000)
            } else {
                if (status == 2) {
                    cm.sendNext("另外，作为你努力探索塔的奖赏，就给你一份小小的礼物吧。", 2540000)
                } else {
                    if (status == 3) {
                        cm.sendOk("戒指箱，起源之塔荣誉勋章，经验值，起源点数全部都已经发放了，打开消耗栏确认一下吧。", 2540000)
                    } else {
                        if (status == 4) {
                            reward()
                        }
                    }
                }
            }
        }
    }
}
var stoneTime = [16, 13, 8, 5, 2];

function reward() {
    cm.curNodeEventEnd(true);
    cm.setInGameDirectionMode(false, true);
    cm.dispose();
    var a = cm.getNumberFromQuestInfo(42002, "f");
    var c = cm.getNumberFromQuestInfo(42002, "tf");
    var j = cm.getNumberFromQuestInfo(42002, "t", 99999999);
    var g = 2028272 - Math.floor((a - 1) / 5);
    cm.gainItem(g, 1);
    var h = cm.getNumberFromQuestInfo(42106, "wtt");
    var b = cm.getNumberFromQuestInfo(42024, "newPoint");
    var e = cm.getNumberFromQuestInfo(42024, "exp");
    cm.起源之塔_奖励UI(a, h, b, e, g, c);
    cm.gainItem(2433840, Math.floor(a * a / 8));
    if (j != 99999999) {
        var d = Math.floor(j / 2 / 1000 / 60);
        for (var f = 0; f < stoneTime.length; f++) {
            while (d > stoneTime[f]) {
                cm.gainItem(2432442 - f, 1);
                d -= stoneTime[f]
            }
        }
    }
    cm.setNumberForQuestInfo(42002, "f", 0);
    cm.setNumberForQuestInfo(42002, "t", 99999999);
    cm.setNumberForQuestInfo(42106, "wtt", 0);
    cm.setNumberForQuestInfo(42024, "newPoint", 0);
    cm.setNumberForQuestInfo(42024, "exp", 0);
    cm.updateInfoQuest(42011, "time=600000;type=1");
    cm.updateHeaderUI(1, 0, 600000, 0, 600000, 42011)
}

function start() {
    status = -1;
    action(1, 0, 0)
};